module game {
    export class Processor_DDZ extends puremvc.SimpleCommand implements puremvc.ICommand {
        public constructor() {
            super();
        }
        public static NAME: string = "Processor_DDZ";
        private ddzProxy: DdzProxy = null;
        /**
         * 注册消息
         */
        public register(): void {
            this.facade.registerCommand("Processor_DDZ", Processor_DDZ);
        }

        public execute(notification: puremvc.INotification): void {
            this.ddzProxy = DdzProxy.getProxy();
            var body: any = notification.getBody();//携带数据
            let msgdata = DataParser.WSReceiveMsg(RegDataDdz, body);
            if (Global.isEmpty(msgdata)) {
                return;
            }
            let mainCmd = msgdata["mainCmd"];
            let subCmd = msgdata["subCmd"];
            let data = msgdata["msgData"];
            if (InstructionsEnum.IS_TEST) {
                console.log("接收：", mainCmd, subCmd, msgdata)
            }
            if (Global.isEmpty(data)) {
                return;
            }
            switch (mainCmd) {
                case 1: {
                    if (subCmd == 100) {//登陆成功
                        this.ddzProxy.login(data);
                    }
                    if (subCmd == 101) {//登陆异常
                        Global.tipShow(data["szDescribeString"]);
                        SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.DDZ);
                        InstructionsEnum.ID_GAME = "";
                    }
                    if (subCmd == 102) { //登陆完成
                        this.ddzProxy.startGameDate();
                    }
                    if (subCmd == 103) { //回到其他房间
                        SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.DDZ);
                        game.AppFacade.instance.sendNotification(PanelNotify.HALL.HALL_RECONNECTGAME, data["wServerID"]);
                    }
                    if (subCmd == 104) {//中途断线重连
                        this.ddzProxy.login(data);
                    }
                    break;
                }

                case 2: {
                    if (subCmd == 101) {//大厅配置
                        this.ddzProxy.getHallInfo(data);
                    };
                    break;
                }
                case 3: {
                    if (subCmd == 100) {//刷新广场人员信息
                        this.ddzProxy.userJoinSquare(data)
                    };
                    if (subCmd == 101) {//
                        this.ddzProxy.getUserInfo(data);
                    }
                    if (subCmd == 102) {//我分配到的座位
                        this.ddzProxy.userStateModify(data);
                    }
                    if (subCmd == 103) {//钱不够入座
                        SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.DDZ)
                        Global.tipShow(data["szDescribeString"])
                    }
                    break;
                }
                case 4: {
                    if (subCmd == 100) {
                        this.ddzProxy.getRoomInfo(data);
                        let obj = new Object();
                        obj["wTableID"] = 65535;
                        obj["wChairID"] = 65535;
                        obj["szInsurePass"] = "";
                        SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.DDZ, RegDataDdz.CMD_GP_UserQuickSitdown, obj)
                    }
                }
                case 8: {
                    if (subCmd == 100) {//
                        this.ddzProxy.getGameStatus(data);
                    };
                    if (subCmd == 103) {//

                    };
                    if (subCmd == 104) {//

                    };
                    if (subCmd == 200) {//
                        if (data["wType"] == 256 || data["wType"] == 512 || data["wType"] == 515) {
                            let obj = {
                                CODE: PanelNotify.DDZ.CLOSE_PLAY_GAME,
                                TEXT: "抱歉！您的金币不足，请前往充值！",
                                NEXT: true,
                            }
                            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_TIP, obj);
                        }
                    };
                    break;
                }
                case 100: {
                    if (subCmd == 100) {
                        //空闲
                        if (data["cbGameStatus"] == 0) {
                            RegDataDdz.MainCMD_MsgId[100][101] = RegDataDdz.free
                        }
                        //叫分
                        if (data["cbGameStatus"] == 100) {
                            RegDataDdz.MainCMD_MsgId[100][101] = RegDataDdz.jiaofen
                        }
                        // 游戏开始
                        if (data["cbGameStatus"] == 101) {
                            RegDataDdz.MainCMD_MsgId[100][101] = RegDataDdz.gameStart
                        }
                    }
                    if (subCmd == 101) {
                        this.ddzProxy.dataRecovery(data);
                    }
                    if (subCmd == 200) {//后端推送消息
                        if (data["wType"] == 515) {
                            Global.tipShow(data["szString"]);
                        } else {
                            EffectUtils.textFadeAway(data["szString"]);
                        }
                    }
                    if (subCmd == 300) {//牌局编号
                        this.ddzProxy.getSerialNumber(data);
                    }
                    break;
                }
                case 200: {
                    if (subCmd == 100) {//发牌
                        this.ddzProxy.startGame(data);
                    };
                    if (subCmd == 101) { //用户叫分
                        this.ddzProxy.userCallScore(data);
                    };
                    if (subCmd == 102) {//叫分完成确定庄家
                        this.ddzProxy.callScoreOver(data);
                    };
                    if (subCmd == 103) {//用户出牌
                        this.ddzProxy.userPlayCards(data);
                    };
                    if (subCmd == 104) {//用户弃牌
                        this.ddzProxy.userGiveUpCards(data);
                    };
                    if (subCmd == 105) {//游戏结束
                        this.ddzProxy.gameOver(data);
                    };
                    if (subCmd == 107) {//空闲状态
                        this.ddzProxy.getOutTime(data);
                    };
                    if (subCmd == 108) {//托管状态
                        this.ddzProxy.setHosting(data);
                    };
                    if (subCmd == 115) {//房间基础倍数
                        DdzVO.getVo().bIsDouble = data["bIsDouble"];
                        DdzVO.getVo().cbIsDoubleNumber = DdzVO.getVo().bIsDouble;
                    };
                    break;
                }
                // case 1000: {
                //     if (subCmd == 1) {
                //          EffectUtils.textFadeAway(data["szString"]);
                //     }
                //     break;
                // }

            }
        }
    }
}
